﻿using BZ.Logger;
using HalconDotNet;
using NDK.Frm;
using NDK.Module.BLL;
using NDK.Module.Model;
using NDK.Motion.BLL;
using NDK.Motion.MachineManager;
using NDK.Motion.MachineResources;
using NDK.Motion.Monitor;
using NDK.Motion.StationLogic;
using NDK.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static NDK.Module.Model.Common;

namespace NDK.Module.StationLogic
{
    [Monitor(Description = "量测1平台工位")]
    public class Measure1 : StationLogicBase
    {
        #region 通用
        //记录当前步骤，用于步骤变化的比较
        private StationStep _curStep = StationStep.WaitMacInit;
        //对外提供工位的步骤变化事件
        public override event PropertyChangedEventHandler PropertyChanged;
        //对外提供唯一实例
        public static Measure1 Instance = new Measure1();
        //私有化的构造函数
        private Measure1() : base()
        {
            Name = "量测1平台";
        }
        //步骤字段、属性
        private StationStep _step = StationStep.WaitMacInit;
        [Monitor(Description = "当前步骤")]
        public StationStep Step
        {
            get
            {
                return _step;
            }
            set
            {
                if (_curStep != value)
                {
                    _step = value;
                    _curStep = value;
                    FileUtils.WriteLogToTxt($"{Step}  CT:{Math.Round((double)swStepTime.ElapsedMilliseconds / 1000, 3)}s", logFold, logBaseInfo, isWriteLog);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(value.ToString()));
                    swStepTime.Restart();
                }
            }
        }
        #endregion

        #region 变量
        public System.Diagnostics.Stopwatch laserSW = new System.Diagnostics.Stopwatch();
        public int 允许治具到接料位 { get; set; }
        public bool 告知2号载具允许接料 { get; set; }
        public bool 告知2号载具允许激光扫描 { get; set; }
        public bool 告知2号载具允许上相机拍照位 { get; set; }
        public bool 告知2号载具允许到出料位 { get; set; }
        public bool 告知中转平台允许到接料位 { get; set; }
        public bool Is屏蔽线体 { get; set; }
        bool IsFristRun3d = false;
        string AxisName = "治具1X轴";
        #endregion

        /// <summary>
        /// 工站初始化
        /// </summary>
        public override void Init()
        {
            base.Init();
            Step = StationStep.WaitMacInit;
            logBaseInfo = "量测1平台";
            ListVacuum = new List<OutputSetting>() { Machine.DicOutputIO["治具1真空吸"] };
            SNCode1 = string.Empty;
            LocalGRRCount = 0;
            告知2号载具允许接料 = true;
            告知2号载具允许激光扫描 = true;
            告知2号载具允许上相机拍照位 = true;
            告知2号载具允许到出料位 = true;
            告知中转平台允许到接料位 = false;
            ONLaser(0);
            OFFLaser(0);
            if (Machine.DicLaser.ContainsKey("侧激光"))
            {
                Machine.DicLaser["侧激光1"].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                Machine.DicLaser["侧激光2"].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                Machine.DicLaser["侧激光3"].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                Machine.DicLaser["侧激光4"].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
            }
            if (!屏蔽1号载具 && !屏蔽2号载具) VehiclesSelect = VehiclesSelectType.双载具运行;
            else if (!屏蔽1号载具) VehiclesSelect = VehiclesSelectType.一号载具运行;
            else if (!屏蔽2号载具) VehiclesSelect = VehiclesSelectType.二号载具运行;
            else VehiclesSelect = VehiclesSelectType.停止运行;
            允许治具到接料位 = 1;
            Machine.DicLocalData = new System.Collections.Concurrent.ConcurrentDictionary<string, MeasureProduct>();

            MotionControl.AxesMove(Machine.DicPos[Name]["接料等待位"]);

            if (Line == "右")
            {
                Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdReq, false);
                Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdComp, false);
                Machine.OmronPLC_Up.WriteBool(stCom_2_PC_PLC_B_0, false);
                Is屏蔽线体 = Machine.OmronPLC_Up.ReadBool(stCom_2_PLC_PC_B_0);
            }
            else
            {
                Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdReq, false);
                Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdComp, false);
                Machine.OmronPLC_Up.WriteBool(stCom_3_PC_PLC_B_0, false);
                Is屏蔽线体 = Machine.OmronPLC_Up.ReadBool(stCom_3_PLC_PC_B_0);
            }
        }

        /// <summary>
        /// 工站动作流程
        /// </summary>
        /// <param name="mode"></param>
        public override void ActionProcess()
        {
            if (VehiclesSelect == VehiclesSelectType.停止运行 || VehiclesSelect == VehiclesSelectType.二号载具运行 || (!手动放料 && Is屏蔽线体))
                return;

            if (StationManager.MachineProductionMode == RunningModeEnum.GRRMode && VehiclesSelect == VehiclesSelectType.双载具运行)
            {
                MessageBox.Show("跑GRR模式必须选择单治具运行");
            }
            try
            {
                switch (Step)
                {
                    case StationStep.WaitMacInit:
                        Step = StationStep.Start;
                        break;
                    case StationStep.Start:
                        if (PublicMethod.OffVacuum(ListVacuum) && MotionControl.AxesMove(Machine.DicPos[Name]["接料等待位"]))
                        {
                            Step = StationStep.等待允许到接料位;
                        }
                        break;
                    case StationStep.等待允许到接料位:
                        switch (VehiclesSelect)
                        {
                            case VehiclesSelectType.双载具运行:
                                if (允许治具到接料位 == 1 && Measure2.Instance.告知1号载具允许接料)
                                {
                                    告知2号载具允许接料 = false;
                                    if (MotionControl.AxesMove(Machine.DicPos[Name]["接料位"]))
                                    {
                                        Step = StationStep.判断手动模式;
                                    }
                                }
                                break;
                            case VehiclesSelectType.一号载具运行:
                                if (MotionControl.AxesMove(Machine.DicPos[Name]["接料位"]))
                                {
                                    Step = StationStep.判断手动模式;
                                }
                                break;
                            case VehiclesSelectType.二号载具运行:
                                break;
                            case VehiclesSelectType.停止运行:
                                break;
                            case VehiclesSelectType.待复位后看状态:
                                break;
                        }
                        break;
                    case StationStep.判断手动模式:
                        if (手动放料)
                            Step = StationStep.手动判断启动;
                        else
                        {
                            if (Line == "右")
                            {
                                Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdReq, true);
                                if (!Machine.OmronPLC_Up.ReadBool(stCom_0_PC_PLC_LdReq))
                                    break;
                            }
                            else
                            {
                                Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdReq, true);
                                if (!Machine.OmronPLC_Up.ReadBool(stCom_1_PC_PLC_LdReq))
                                    break;
                            }
                            Step = StationStep.等待PLC到位信号;
                        }
                        break;
                    case StationStep.等待PLC到位信号:
                        if (Line == "右")
                        {
                            if (Machine.OmronPLC_Up.ReadBool(stCom_0_PLC_PC_UldInPos))
                            {
                                if (ReadBaracode("2", true, out string snstr))
                                {
                                    SNCode1 = snstr;
                                    if (PublicMethod.OpenVacuum(ListVacuum))
                                    {
                                        Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdComp, true);
                                        if (Machine.OmronPLC_Up.ReadBool(stCom_0_PC_PLC_LdComp))
                                            Step = StationStep.等待PLC放料完成;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Machine.OmronPLC_Up.ReadBool(stCom_1_PLC_PC_UldInPos))
                            {
                                if (ReadBaracode("3", true, out string snstr))
                                {
                                    SNCode1 = snstr;
                                    if (PublicMethod.OpenVacuum(ListVacuum))
                                    {
                                        Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdComp, true);
                                        if (Machine.OmronPLC_Up.ReadBool(stCom_1_PC_PLC_LdComp))
                                            Step = StationStep.等待PLC放料完成;
                                    }
                                }
                            }
                        }
                        break;
                    case StationStep.等待PLC放料完成:
                        if (Line == "右")
                        {
                            if (!Machine.OmronPLC_Up.ReadBool(stCom_0_PLC_PC_UldCompAck))
                                break;
                            Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdReq, false);
                            Machine.OmronPLC_Up.WriteBool(stCom_0_PC_PLC_LdComp, false);
                        }
                        else
                        {
                            if (!Machine.OmronPLC_Up.ReadBool(stCom_1_PLC_PC_UldCompAck))

                                break;
                            Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdReq, false);
                            Machine.OmronPLC_Up.WriteBool(stCom_1_PC_PLC_LdComp, false);
                        }
                        Step = StationStep.接料位信号处理;
                        break;
                    case StationStep.手动判断启动:
                        if (Frm_Main.Instance.chb1.Checked)
                        {
                            if (!启动一次)
                            {
                                启动一次 = true;
                            }
                        }
                        if (启动一次)
                        {
                            if (!Frm_Main.Instance.chb1.Checked)
                            {
                                MessageBox.Show($"请确定{Line}线治具1检测物料是否放在治具上");
                            }
                            if (PublicMethod.OpenVacuum(ListVacuum))
                            {
                                启动一次 = false;
                                ReadBaracode(Line == "右" ? "2" : "3", false, out string str);
                                SNCode1 = str;
                                Step = StationStep.接料位信号处理;
                            }
                        }
                        break;
                    case StationStep.接料位信号处理:
                        if (StationManager.MachineProductionMode == RunningModeEnum.GRRMode && LocalGRRCount > 0)
                        {
                            SNCode1 = $"{SNCode1}_{LocalGRRCount}";
                            Machine.AddDicLocalData(SNCode1, new MeasureProduct() { SN = $"{SNCode1.Split('_')[0]}_{LocalGRRCount}", whichBlock = whichBlock, Position = Line == "右" ? "2" : "3" });
                        }
                        Step = StationStep.移动到侧相机拍照位;
                        break;
                    case StationStep.移动到侧相机拍照位:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["侧相机拍照位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                Machine.DicLight["侧CCD光源1"].Opens(ConsumerAdress, ProjectName, "侧相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].SideCam_1 = PublicMethod.GradImage("侧相机", Machine.DirExp["侧相机"]);
                                Machine.DicLight["侧CCD光源2"].Opens(ConsumerAdress, ProjectName, "侧相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].SideCam_2 = PublicMethod.GradImage("侧相机", Machine.DirExp["侧相机"]);
                                Machine.DicLight["侧CCD光源3"].Opens(ConsumerAdress, ProjectName, "侧相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].SideCam_3 = PublicMethod.GradImage("侧相机", Machine.DirExp["侧相机"]);
                                if (GetImageStatus(new List<string>() { "侧相机1", "侧相机2", "侧相机3" }, new List<HImage>() { Machine.DicLocalData[SNCode1].SideCam_1, Machine.DicLocalData[SNCode1].SideCam_2,
                                    Machine.DicLocalData[SNCode1].SideCam_3 }, Step) == Step)
                                {
                                    break;
                                }
                                EventVisoion.OnLoadingCameraRefresh(new EventVisoion.ImageRefreshEventArgs()
                                {
                                    SN = SNCode1
                                });
                                Task.Run(() => { Machine.DicLight["侧CCD光源3"].Close(); });
                            }
                            Step = StationStep.侧相机移动到安全位;
                        }
                        break;
                    case StationStep.侧相机移动到安全位:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["侧相机安全位"]))
                        {
                            Step = StationStep.等待允许激光扫描;
                        }
                        break;
                    case StationStep.等待允许激光扫描:
                        if (Measure2.Instance.告知1号载具允许激光扫描)
                        {
                            Machine.DicOutputIO["脉冲切换"].ON();
                            if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                            {
                                if (ProjectName.Contains("4080"))
                                    Step = StationStep.移动到短边起始位_4080;
                                else if (ProjectName.Contains("4081"))
                                    Step = StationStep.移动到短边起始位_4081;
                                else if (ProjectName.Contains("4084"))
                                    Step = StationStep.移动到短边起始位_4084;
                                else if (ProjectName.Contains("4062") && ConsumerAdress != "NVT")
                                    Step = StationStep.移动到短边起始位_4062;
                                else if (ProjectName.Contains("4062") && ConsumerAdress == "NVT")
                                    Step = StationStep.移动到短边起始位_4062_NVT;
                                if (Step != StationStep.等待允许激光扫描)
                                {
                                    允许治具到接料位 = 2;
                                    告知2号载具允许激光扫描 = false;
                                    告知2号载具允许上相机拍照位 = false;
                                    告知2号载具允许接料 = true;
                                    IsFristRun3d = true;
                                }
                            }
                        }
                        break;

                    #region 4080
                    case StationStep.移动到短边起始位_4080:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                foreach (string item in Machine.DicLaser.Keys)
                                {
                                    if (item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                                    }
                                }
                                ONLaser(4);
                                Machine.DicLaser["上激光"].Start();
                            }
                            Step = StationStep.移动到短边终点位_4080;
                        }
                        break;
                    case StationStep.移动到短边终点位_4080:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(4);
                            }
                            Step = StationStep.移动到长边起始位_4080;
                        }
                        break;
                    case StationStep.移动到长边起始位_4080:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                ONLaser(4);
                            }
                            Step = StationStep.移动到长边终点位_4080;
                        }
                        break;

                    case StationStep.移动到长边终点位_4080:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(4);
                            }
                            Step = StationStep.上相机拍照位1;
                        }
                        break;
                    #endregion

                    #region 4081
                    case StationStep.移动到短边起始位_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                foreach (var item in Machine.DicLaser.Keys)
                                {
                                    if (item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                                    }
                                }
                                Machine.DicLaser["上激光"].Start();
                                ONLaser(5);
                            }
                            Step = StationStep.移动到短边终点位_4081;
                        }
                        break;
                    case StationStep.移动到短边终点位_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(5);
                            }
                            Step = StationStep.移动到长边起始位_4081;
                        }
                        break;

                    case StationStep.移动到长边起始位_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                ONLaser(4);
                            }
                            Step = StationStep.移动到长边终点位_4081;
                        }
                        break;
                    case StationStep.移动到长边终点位_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(4);
                            }
                            Step = StationStep.移动到长边起始位1_4081;
                        }
                        break;
                    case StationStep.移动到长边起始位1_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                ONLaser(1);
                            }
                            Step = StationStep.移动到长边终点位1_4081;
                        }
                        break;
                    case StationStep.移动到长边终点位1_4081:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(1);
                            }
                            Step = StationStep.上相机拍照位1;
                        }
                        break;
                    #endregion

                    #region 4084
                    case StationStep.移动到短边起始位_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                foreach (var item in Machine.DicLaser.Keys)
                                {
                                    if (item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                                    }
                                }
                                ONLaser(5);
                            }
                            Step = StationStep.移动到短边终点位_4084;
                        }
                        break;
                    case StationStep.移动到短边终点位_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(5);
                            }
                            Step = StationStep.移动到短边起始位1_4084;
                        }
                        break;

                    case StationStep.移动到短边起始位1_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                ONLaser(2);
                            }
                            Step = StationStep.移动到短边终点位1_4084;
                        }
                        break;
                    case StationStep.移动到短边终点位1_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(2);
                            }
                            Step = StationStep.移动到长边起始位_4084;
                        }
                        break;
                    case StationStep.移动到长边起始位_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                Machine.DicLaser["上激光"].Start();
                                ONLaser(4);
                            }
                            Step = StationStep.移动到长边终点位_4084;
                        }
                        break;
                    case StationStep.移动到长边终点位_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(4);
                            }
                            Step = StationStep.移动到长边起始位1_4084;
                        }
                        break;
                    case StationStep.移动到长边起始位1_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                ONLaser(7);
                            }
                            Step = StationStep.移动到长边终点位1_4084;
                        }
                        break;
                    case StationStep.移动到长边终点位1_4084:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                OFFLaser(7);
                            }
                            Step = StationStep.上相机拍照位1;
                        }
                        break;
                    #endregion

                    #region 4062 
                    case StationStep.移动到短边起始位_4062:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                foreach (var item in Machine.DicLaser.Keys)
                                {
                                    if (item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                                    }
                                }
                            }

                            List<InterpolationParam> Params = new List<InterpolationParam>() {

                            new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["侧激光1触发"], Machine.DicOutputIO["侧激光2触发"], Machine.DicOutputIO["侧激光3触发"],  Machine.DicOutputIO["侧激光4触发"] },
                                 SelectType=2
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["短边起始位"],
                                EndPosiiton=Machine.DicPos[Name]["短边终点位"],
                                axisName=AxisName,
                                length=3,
                                SelectType=3
                            },
                                     new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["侧激光1触发"], Machine.DicOutputIO["侧激光2触发"], Machine.DicOutputIO["侧激光3触发"],  Machine.DicOutputIO["侧激光4触发"] },
                                 SelectType=4
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["短边起始位"],
                                EndPosiiton=Machine.DicPos[Name]["短边终点位"],
                                axisName=AxisName,
                                length=3,
                                SelectType=5
                            }

                            };

                            if (MotionControl.InterpolationMotion(Params))
                            {
                                Step = StationStep.移动到短边起始位1_4062;
                            }
                        }
                        break;
                    case StationStep.移动到短边起始位1_4062:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位1"]))
                        {
                            List<InterpolationParam> Params = new List<InterpolationParam>() {

                            new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){  Machine.DicOutputIO["侧激光3触发"]},
                                 SelectType=2
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["短边起始位1"],
                                EndPosiiton=Machine.DicPos[Name]["短边终点位1"],
                                axisName=AxisName,
                                length=3,
                                SelectType=3
                            },
                                     new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["侧激光3触发"] },
                                 SelectType=4
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["短边起始位1"],
                                EndPosiiton=Machine.DicPos[Name]["短边终点位1"],
                                axisName=AxisName,
                                length=3,
                                SelectType=5
                            }
                            };

                            if (!MotionControl.InterpolationMotion(Params))
                            {
                                Step = StationStep.移动到短边起始位_4062;
                                break;
                            }
                            Step = StationStep.移动到长边起始位_4062;
                        }
                        break;
                    case StationStep.移动到长边起始位_4062:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位"]))
                        {
                            List<InterpolationParam> Params = new List<InterpolationParam>() {

                            new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["侧激光1触发"], Machine.DicOutputIO["侧激光2触发"], Machine.DicOutputIO["侧激光3触发"], Machine.DicOutputIO["上激光触发"]},
                                 SelectType=2
                            },
                            new InterpolationParam(){
                               delay=50,
                                 SelectType=6
                            },
                            new InterpolationParam(){
                               Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["上激光触发"]},
                                 SelectType=4
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["长边起始位"],
                                EndPosiiton=Machine.DicPos[Name]["长边终点位"],
                                axisName=AxisName,
                                length=3,
                                SelectType=3
                            },
                                     new InterpolationParam(){
                               Outputs=new List<OutputSetting>(){ Machine.DicOutputIO["侧激光1触发"], Machine.DicOutputIO["侧激光2触发"], Machine.DicOutputIO["侧激光3触发"]},
                                 SelectType=4
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["长边起始位"],
                                EndPosiiton=Machine.DicPos[Name]["长边终点位"],
                                axisName=AxisName,
                                length=3,
                                SelectType=5
                            }
                            };

                            if (!MotionControl.InterpolationMotion(Params))
                            {
                                Step = StationStep.移动到短边起始位_4062;
                                break;
                            }
                            Step = StationStep.移动到长边扫描安全位_4062;
                        }
                        break;
                    case StationStep.移动到长边扫描安全位_4062:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边扫描安全位"]))
                            Step = StationStep.移动到长边起始位1_4062;
                        break;
                    case StationStep.移动到长边起始位1_4062:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位1"]))
                        {
                            List<InterpolationParam> Params = new List<InterpolationParam>() {

                            new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){  Machine.DicOutputIO["侧激光3触发"],  Machine.DicOutputIO["侧激光4触发"] },
                                 SelectType=2
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["长边起始位1"],
                                EndPosiiton=Machine.DicPos[Name]["长边终点位1"],
                                axisName=AxisName,
                                length=3,
                                SelectType=3
                            },
                                     new InterpolationParam(){
                                Outputs=new List<OutputSetting>(){  Machine.DicOutputIO["侧激光3触发"],  Machine.DicOutputIO["侧激光4触发"] },
                                 SelectType=4
                            },
                            new InterpolationParam(){
                                StartPosiiton=Machine.DicPos[Name]["长边起始位1"],
                                EndPosiiton=Machine.DicPos[Name]["长边终点位1"],
                                axisName=AxisName,
                                length=3,
                                SelectType=5
                            }
                            };


                            if (!MotionControl.InterpolationMotion(Params))
                            {
                                Step = StationStep.移动到短边起始位_4062;
                                break;
                            }
                            Step = StationStep.上相机拍照位1;
                        }
                        break;
                    #endregion

                    #region 4062 NVT
                    case StationStep.移动到短边起始位_4062_NVT:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                if (!IsFristRun3d)
                                    Thread.Sleep(1000);
                                foreach (var item in Machine.DicLaser.Keys)
                                {
                                    if (item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].CQueneHeightImage = new System.Collections.Concurrent.ConcurrentQueue<HImage>();
                                    }
                                }

                                int LocalPos = Convert.ToInt32(Machine.DicPos[Name]["短边起始位"].AxisList.Find(x => x.Name == AxisName).GetPos() * 1000);
                                int StartPos = Convert.ToInt32(Machine.DicPos[Name]["短边起始位"].GetPos(AxisName) * 1000);
                                int EndPos = Convert.ToInt32(Machine.DicPos[Name]["短边终点位"].GetPos(AxisName) * 1000);

                                if (!MotionControl.CMP_Air(new int[] { 0, 1, 2, 3 }, new int[] { LocalPos + (StartPos - EndPos) > 0 ? -500 : 500, EndPos + (StartPos - EndPos) > 0 ? 4000 : -4000 }, LocalPos))
                                {
                                    if (AlarmPause($"{logBaseInfo}飞拍设定失败", $"{Step}飞拍设定失败：", "请检查Mini飞拍是否存在异常", " 再次拍照", "忽略继续") == DialogResult.OK)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位"]))
                            {
                                Step = StationStep.移动到短边起始位1_4062_NVT;
                            }
                        }
                        break;
                    case StationStep.移动到短边起始位1_4062_NVT:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["短边起始位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                int LocalPos = Convert.ToInt32(Machine.DicPos[Name]["短边起始位1"].AxisList.Find(x => x.Name == AxisName).GetPos() * 1000);
                                int StartPos = Convert.ToInt32(Machine.DicPos[Name]["短边起始位1"].GetPos(AxisName) * 1000);
                                int EndPos = Convert.ToInt32(Machine.DicPos[Name]["短边终点位1"].GetPos(AxisName) * 1000);

                                if (!MotionControl.CMP_Air(new int[] { 2 }, new int[] { LocalPos + (StartPos - EndPos) > 0 ? -500 : 500, EndPos + (StartPos - EndPos) > 0 ? 4000 : -4000 }, LocalPos))
                                {
                                    if (AlarmPause($"{logBaseInfo}飞拍设定失败", $"{Step}飞拍设定失败：", "请检查Mini飞拍是否存在异常", " 再次拍照", "忽略继续") == DialogResult.OK)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!MotionControl.AxesMove(Machine.DicPos[Name]["短边终点位1"]))
                            {
                                IsFristRun3d = false;
                                Step = StationStep.移动到短边起始位_4062_NVT;
                                break;
                            }
                            Step = StationStep.移动到长边起始位_4062_NVT;
                        }
                        break;
                    case StationStep.移动到长边起始位_4062_NVT:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                int LocalPos = Convert.ToInt32(Machine.DicPos[Name]["长边起始位"].AxisList.Find(x => x.Name == AxisName).GetPos() * 1000);
                                int StartPos = Convert.ToInt32(Machine.DicPos[Name]["长边起始位"].GetPos(AxisName) * 1000);
                                int EndPos = Convert.ToInt32(Machine.DicPos[Name]["长边终点位"].GetPos(AxisName) * 1000);
                                if (!MotionControl.CMP_Air(new int[] { 0, 1, 2 }, new int[] { LocalPos + (StartPos - EndPos) > 0 ? -500 : 500, EndPos + (StartPos - EndPos) > 0 ? 4000 : -4000 }, LocalPos))
                                {
                                    if (AlarmPause($"{logBaseInfo}飞拍设定失败", $"{Step}飞拍设定失败：", "请检查Mini飞拍是否存在异常", " 再次拍照", "忽略继续") == DialogResult.OK)
                                    {
                                        break;
                                    }
                                }
                                Machine.DicLaser["上激光"].Start();
                            }
                            if (!MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位"]))
                            {
                                IsFristRun3d = false;
                                Step = StationStep.移动到短边起始位_4062_NVT;
                                break;
                            }
                            Step = StationStep.移动到长边扫描安全位_4062_NVT;
                        }
                        break;
                    case StationStep.移动到长边扫描安全位_4062_NVT:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边扫描安全位"]))
                            Step = StationStep.移动到长边起始位1_4062_NVT;
                        break;
                    case StationStep.移动到长边起始位1_4062_NVT:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["长边起始位1"]))
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                int LocalPos = Convert.ToInt32(Machine.DicPos[Name]["长边起始位1"].AxisList.Find(x => x.Name == AxisName).GetPos() * 1000);
                                int StartPos = Convert.ToInt32(Machine.DicPos[Name]["长边起始位1"].GetPos(AxisName) * 1000);
                                int EndPos = Convert.ToInt32(Machine.DicPos[Name]["长边终点位1"].GetPos(AxisName) * 1000);
                                if (!MotionControl.CMP_Air(new int[] { 2, 3 }, new int[] { LocalPos + (StartPos - EndPos) > 0 ? -500 : 500, EndPos + (StartPos - EndPos) > 0 ? 4000 : -4000 }, LocalPos))
                                {
                                    if (AlarmPause($"{logBaseInfo}飞拍设定失败", $"{Step}飞拍设定失败：", "请检查Mini飞拍是否存在异常", " 再次拍照", "忽略继续") == DialogResult.OK)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!MotionControl.AxesMove(Machine.DicPos[Name]["长边终点位1"]))
                            {
                                IsFristRun3d = false;
                                Step = StationStep.移动到短边起始位_4062_NVT;
                                break;
                            }
                            Step = StationStep.上相机拍照位1;
                        }
                        break;
                    #endregion

                    case StationStep.上相机拍照位1:
                        if (Measure2.Instance.告知1号载具允许上相机拍照位)
                        {
                            if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                            {
                                if (MotionControl.AxesMove(Machine.DicPos[Name]["上相机拍照位1"]))
                                {
                                    if (!ProjectName.Contains("4062"))
                                    {
                                        Machine.DicLight[治具1上CCD光源1名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                        PublicMethod.Delay(光源打开延时);
                                        Machine.DicLocalData[SNCode1].UpCamImage_1 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                        Machine.DicLight[治具1上CCD光源2名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                        PublicMethod.Delay(光源打开延时);
                                        Machine.DicLocalData[SNCode1].UpCamImage_2 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                        if (GetImageStatus(new List<string>() { "上相机1", "上相机2" }, new List<HImage>() { Machine.DicLocalData[SNCode1].UpCamImage_1, Machine.DicLocalData[SNCode1].UpCamImage_2 }, Step) != StationStep.End)
                                        {
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        Machine.DicLight[治具1上CCD光源1名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                        PublicMethod.Delay(光源打开延时);
                                        Machine.DicLocalData[SNCode1].UpCamImage_1 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                        if (GetImageStatus(new List<string>() { "上相机1" }, new List<HImage>() { Machine.DicLocalData[SNCode1].UpCamImage_1 }, Step) != StationStep.End)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            laserSW.Restart();
                            Step = StationStep.判断激光图是否扫全;
                        }
                        break;
                    case StationStep.判断激光图是否扫全:
                        if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                        {
                            if (laserSW.ElapsedMilliseconds > 5000)
                            {
                                if (AlarmPause($"激光群组采图异常", $"激光群组: 采集异常：", "请检查相机是否掉线及相机参数是否存在异常", " 重新扫描", "忽略继续") == DialogResult.OK)
                                {
                                    laserSW.Restart();
                                    HImage hImage1 = null;
                                    if (GetImageStatus(new List<string>() { "侧激光1" }, new List<HImage>() { hImage1 }, Step) == Step)
                                    {

                                    }
                                    if (ProjectName.Contains("4080"))
                                        Step = StationStep.移动到短边起始位_4080;
                                    else if (ProjectName.Contains("4081"))
                                        Step = StationStep.移动到短边起始位_4081;
                                    else if (ProjectName.Contains("4084"))
                                        Step = StationStep.移动到短边起始位_4084;
                                    else if (ProjectName.Contains("4062") && ConsumerAdress != "NVT")
                                        Step = StationStep.移动到短边起始位_4062;
                                    else if (ProjectName.Contains("4062") && ConsumerAdress == "NVT")
                                        Step = StationStep.移动到短边起始位_4062_NVT;
                                    break;
                                }
                            }
                            if (ProjectName.Contains("4080"))
                            {
                                if (Machine.DicLaser["侧激光1"].CQueneHeightImage.Count == 2 && Machine.DicLaser["侧激光2"].CQueneHeightImage.Count == 2
                                    && Machine.DicLaser["侧激光4"].CQueneHeightImage.Count == 2)
                                {
                                    //短边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage1);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage2);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage4);

                                    //长边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage11);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage12);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage14);

                                    hImage1.GetImageSize(out int width1, out int height1);
                                    hImage2.GetImageSize(out int width2, out int height2);
                                    hImage4.GetImageSize(out int width4, out int height4);

                                    hImage11.GetImageSize(out int width11, out int height11);
                                    hImage12.GetImageSize(out int width12, out int height12);
                                    hImage14.GetImageSize(out int width14, out int height14);
                                    try
                                    {
                                        Machine.DicLocalData[SNCode1].SideLaser_短边1_1 = hImage1.CropRectangle1(Convert.ToInt32(短边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度1_1.Trim().Split(',')[1]), width1);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边2_1 = hImage2.CropRectangle1(Convert.ToInt32(短边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度2_1.Trim().Split(',')[1]), width2);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边4_1 = hImage4.CropRectangle1(Convert.ToInt32(短边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度4_1.Trim().Split(',')[1]), width4);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_3 = hImage11.CropRectangle1(Convert.ToInt32(长边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_1.Trim().Split(',')[1]), width11);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边2_3 = hImage12.CropRectangle1(Convert.ToInt32(长边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度2_1.Trim().Split(',')[1]), width12);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边4_3 = hImage14.CropRectangle1(Convert.ToInt32(长边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度4_1.Trim().Split(',')[1]), width14);
                                    }
                                    catch
                                    {
                                        string path3D_err = $"D:\\1治具\\{SNCode1}";
                                        if (!FileUtils.IsExistDirectory(path3D_err)) FileUtils.CreateDirectory(path3D_err);
                                        HOperatorSet.WriteImage(hImage1, "tiff", 0, $"{path3D_err}\\hImage1.tiff");
                                        HOperatorSet.WriteImage(hImage2, "tiff", 0, $"{path3D_err}\\hImage2.tiff");
                                        HOperatorSet.WriteImage(hImage4, "tiff", 0, $"{path3D_err}\\hImage4.tiff");
                                        HOperatorSet.WriteImage(hImage11, "tiff", 0, $"{path3D_err}\\hImage11.tiff");
                                        HOperatorSet.WriteImage(hImage12, "tiff", 0, $"{path3D_err}\\hImage12.tiff");
                                        HOperatorSet.WriteImage(hImage14, "tiff", 0, $"{path3D_err}\\hImage14.tiff");
                                        MessageBox.Show("侧激光图像裁剪异常！"); ;
                                    }

                                    hImage1 = Machine.DicLaser["上激光"].HeightImage(5000);
                                    if (GetImageStatus(new List<string>() { "上激光" }, new List<HImage>() { hImage1 }, Step) != StationStep.End)
                                    {
                                        Step = StationStep.移动到短边起始位_4080;
                                        break;
                                    }
                                    hImage1.GetImageSize(out width1, out height1);

                                    Machine.DicLocalData[SNCode1].UpLaser = hImage1.CropRectangle1(Convert.ToInt32(上激光长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(上激光长度1_1.Trim().Split(',')[1]), width1);
                                    EventVisoion.OnCarrierUpLaserRefresh(new EventVisoion.ImageRefreshEventArgs()
                                    {
                                        SN = SNCode1
                                    });
                                    Step = StationStep.移动到上相机拍照位2拍照;
                                }
                            }
                            else if (ProjectName.Contains("4081"))
                            {
                                if (Machine.DicLaser["侧激光1"].CQueneHeightImage.Count == 3 && Machine.DicLaser["侧激光2"].CQueneHeightImage.Count == 2
                               && Machine.DicLaser["侧激光3"].CQueneHeightImage.Count == 1 && Machine.DicLaser["侧激光4"].CQueneHeightImage.Count == 2)
                                {
                                    //短边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage1);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage2);
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage3);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage4);

                                    //长边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage11);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage12);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage14);

                                    //长边1
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage21);


                                    hImage1.GetImageSize(out int width1, out int height1);
                                    hImage2.GetImageSize(out int width2, out int height2);
                                    hImage3.GetImageSize(out int width3, out int height3);
                                    hImage4.GetImageSize(out int width4, out int height4);

                                    hImage11.GetImageSize(out int width11, out int height11);
                                    hImage12.GetImageSize(out int width12, out int height12);
                                    hImage14.GetImageSize(out int width14, out int height14);

                                    hImage21.GetImageSize(out int width21, out int height21);

                                    try
                                    {
                                        Machine.DicLocalData[SNCode1].SideLaser_短边1_1 = hImage1.CropRectangle1(Convert.ToInt32(短边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度1_1.Trim().Split(',')[1]), width1);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边2_1 = hImage2.CropRectangle1(Convert.ToInt32(短边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度2_1.Trim().Split(',')[1]), width2);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边3_1 = hImage3.CropRectangle1(Convert.ToInt32(短边长度3_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度3_1.Trim().Split(',')[1]), width3);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边4_1 = hImage4.CropRectangle1(Convert.ToInt32(短边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度4_1.Trim().Split(',')[1]), width4);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_3 = hImage11.CropRectangle1(Convert.ToInt32(长边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_1.Trim().Split(',')[1]), width11);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边2_3 = hImage12.CropRectangle1(Convert.ToInt32(长边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度2_1.Trim().Split(',')[1]), width12);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边4_3 = hImage14.CropRectangle1(Convert.ToInt32(长边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度4_1.Trim().Split(',')[1]), width14);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_4 = hImage21.CropRectangle1(Convert.ToInt32(长边长度1_2.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_2.Trim().Split(',')[1]), width21);
                                    }
                                    catch
                                    {
                                        string path3D_err = $"D:\\1治具\\{SNCode1}";
                                        if (!FileUtils.IsExistDirectory(path3D_err)) FileUtils.CreateDirectory(path3D_err);
                                        HOperatorSet.WriteImage(hImage1, "tiff", 0, $"{path3D_err}\\hImage1.tiff");
                                        HOperatorSet.WriteImage(hImage2, "tiff", 0, $"{path3D_err}\\hImage2.tiff");
                                        HOperatorSet.WriteImage(hImage3, "tiff", 0, $"{path3D_err}\\hImage3.tiff");
                                        HOperatorSet.WriteImage(hImage4, "tiff", 0, $"{path3D_err}\\hImage4.tiff");
                                        HOperatorSet.WriteImage(hImage11, "tiff", 0, $"{path3D_err}\\hImage11.tiff");
                                        HOperatorSet.WriteImage(hImage12, "tiff", 0, $"{path3D_err}\\hImage12.tiff");
                                        HOperatorSet.WriteImage(hImage14, "tiff", 0, $"{path3D_err}\\hImage14.tiff");
                                        HOperatorSet.WriteImage(hImage21, "tiff", 0, $"{path3D_err}\\hImage21.tiff");
                                        MessageBox.Show("侧激光图像裁剪异常！"); ;
                                    }

                                    hImage1 = Machine.DicLaser["上激光"].HeightImage(5000);
                                    if (GetImageStatus(new List<string>() { "上激光" }, new List<HImage>() { hImage1 }, Step) != StationStep.End)
                                    {
                                        Step = StationStep.移动到短边起始位_4081;
                                        break;
                                    }
                                    hImage1.GetImageSize(out width1, out height1);

                                    Machine.DicLocalData[SNCode1].UpLaser = hImage1.CropRectangle1(Convert.ToInt32(上激光长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(上激光长度1_1.Trim().Split(',')[1]), width1);
                                    EventVisoion.OnCarrierUpLaserRefresh(new EventVisoion.ImageRefreshEventArgs()
                                    {
                                        SN = SNCode1
                                    });
                                    Step = StationStep.移动到上相机拍照位2拍照;
                                }
                            }
                            else if (ProjectName.Contains("4084"))
                            {
                                if (Machine.DicLaser["侧激光1"].CQueneHeightImage.Count == 3 && Machine.DicLaser["侧激光2"].CQueneHeightImage.Count == 2
                               && Machine.DicLaser["侧激光3"].CQueneHeightImage.Count == 1 && Machine.DicLaser["侧激光4"].CQueneHeightImage.Count == 4)
                                {
                                    //短边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage1);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage2);
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage3);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage4);

                                    //短边1
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage14);

                                    //长边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage21);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage22);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage24);

                                    //长边1
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage31);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage34);


                                    hImage1.GetImageSize(out int width1, out int height1);
                                    hImage2.GetImageSize(out int width2, out int height2);
                                    hImage3.GetImageSize(out int width3, out int height3);
                                    hImage4.GetImageSize(out int width4, out int height4);

                                    hImage14.GetImageSize(out int width14, out int height14);

                                    hImage21.GetImageSize(out int width21, out int height21);
                                    hImage22.GetImageSize(out int width22, out int height22);
                                    hImage24.GetImageSize(out int width24, out int height24);

                                    hImage31.GetImageSize(out int width31, out int height31);
                                    hImage34.GetImageSize(out int width34, out int height34);

                                    try
                                    {
                                        Machine.DicLocalData[SNCode1].SideLaser_短边1_1 = hImage1.CropRectangle1(Convert.ToInt32(短边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度1_1.Trim().Split(',')[1]), width1);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边2_1 = hImage2.CropRectangle1(Convert.ToInt32(短边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度2_1.Trim().Split(',')[1]), width2);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边3_1 = hImage3.CropRectangle1(Convert.ToInt32(短边长度3_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度3_1.Trim().Split(',')[1]), width3);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边4_1 = hImage4.CropRectangle1(Convert.ToInt32(短边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度4_1.Trim().Split(',')[1]), width4);

                                        Machine.DicLocalData[SNCode1].SideLaser_短边4_2 = hImage14.CropRectangle1(Convert.ToInt32(短边长度4_2.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度4_2.Trim().Split(',')[1]), width14);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_3 = hImage21.CropRectangle1(Convert.ToInt32(长边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_1.Trim().Split(',')[1]), width21);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边2_3 = hImage22.CropRectangle1(Convert.ToInt32(长边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度2_1.Trim().Split(',')[1]), width22);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边4_3 = hImage24.CropRectangle1(Convert.ToInt32(长边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度4_1.Trim().Split(',')[1]), width24);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_4 = hImage31.CropRectangle1(Convert.ToInt32(长边长度1_2.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_2.Trim().Split(',')[1]), width31);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边4_4 = hImage34.CropRectangle1(Convert.ToInt32(长边长度4_2.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度4_2.Trim().Split(',')[1]), width34);
                                    }
                                    catch
                                    {
                                        string path3D_err = $"D:\\1治具\\{SNCode1}";
                                        if (!FileUtils.IsExistDirectory(path3D_err)) FileUtils.CreateDirectory(path3D_err);
                                        HOperatorSet.WriteImage(hImage1, "tiff", 0, $"{path3D_err}\\hImage1.tiff");
                                        HOperatorSet.WriteImage(hImage2, "tiff", 0, $"{path3D_err}\\hImage2.tiff");
                                        HOperatorSet.WriteImage(hImage3, "tiff", 0, $"{path3D_err}\\hImage3.tiff");
                                        HOperatorSet.WriteImage(hImage4, "tiff", 0, $"{path3D_err}\\hImage4.tiff");
                                        HOperatorSet.WriteImage(hImage14, "tiff", 0, $"{path3D_err}\\hImage14.tiff");
                                        HOperatorSet.WriteImage(hImage21, "tiff", 0, $"{path3D_err}\\hImage21.tiff");
                                        HOperatorSet.WriteImage(hImage22, "tiff", 0, $"{path3D_err}\\hImage22.tiff");
                                        HOperatorSet.WriteImage(hImage24, "tiff", 0, $"{path3D_err}\\hImage24.tiff");
                                        HOperatorSet.WriteImage(hImage31, "tiff", 0, $"{path3D_err}\\hImage31.tiff");
                                        HOperatorSet.WriteImage(hImage34, "tiff", 0, $"{path3D_err}\\hImage34.tiff");
                                        MessageBox.Show("侧激光图像裁剪异常！"); ;
                                    }

                                    hImage1 = Machine.DicLaser["上激光"].HeightImage(5000);
                                    if (GetImageStatus(new List<string>() { "上激光" }, new List<HImage>() { hImage1 }, Step) != StationStep.End)
                                    {
                                        Step = StationStep.移动到短边起始位_4084;
                                        break;
                                    }
                                    hImage1.GetImageSize(out width1, out height1);

                                    Machine.DicLocalData[SNCode1].UpLaser = hImage1.CropRectangle1(Convert.ToInt32(上激光长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(上激光长度1_1.Trim().Split(',')[1]), width1);
                                    EventVisoion.OnCarrierUpLaserRefresh(new EventVisoion.ImageRefreshEventArgs()
                                    {
                                        SN = SNCode1
                                    });
                                    Step = StationStep.移动到上相机拍照位2拍照;
                                }
                            }
                            else if (ProjectName.Contains("4062"))
                            {
                                if (Machine.DicLaser["侧激光1"].CQueneHeightImage.Count == 2 && Machine.DicLaser["侧激光2"].CQueneHeightImage.Count == 2
                           && Machine.DicLaser["侧激光3"].CQueneHeightImage.Count == 4 && Machine.DicLaser["侧激光4"].CQueneHeightImage.Count == 2)
                                {
                                    //短边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage1);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage2);
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage3);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage4);

                                    //短边1
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage13);

                                    //长边
                                    Machine.DicLaser["侧激光1"].CQueneHeightImage.TryDequeue(out var hImage21);
                                    Machine.DicLaser["侧激光2"].CQueneHeightImage.TryDequeue(out var hImage22);
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage23);

                                    //长边1
                                    Machine.DicLaser["侧激光3"].CQueneHeightImage.TryDequeue(out var hImage33);
                                    Machine.DicLaser["侧激光4"].CQueneHeightImage.TryDequeue(out var hImage34);


                                    hImage1.GetImageSize(out int width1, out int height1);
                                    hImage2.GetImageSize(out int width2, out int height2);
                                    hImage3.GetImageSize(out int width3, out int height3);
                                    hImage4.GetImageSize(out int width4, out int height4);

                                    hImage13.GetImageSize(out int width13, out int height13);

                                    hImage21.GetImageSize(out int width21, out int height21);
                                    hImage22.GetImageSize(out int width22, out int height22);
                                    hImage23.GetImageSize(out int width23, out int height23);

                                    hImage33.GetImageSize(out int width33, out int height33);
                                    hImage34.GetImageSize(out int width34, out int height34);

                                    try
                                    {
                                        Machine.DicLocalData[SNCode1].SideLaser_短边1_1 = hImage1.CropRectangle1(Convert.ToInt32(短边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度1_1.Trim().Split(',')[1]), width1);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边2_1 = hImage2.CropRectangle1(Convert.ToInt32(短边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度2_1.Trim().Split(',')[1]), width2);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边3_1 = hImage3.CropRectangle1(Convert.ToInt32(短边长度3_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度3_1.Trim().Split(',')[1]), width3);
                                        Machine.DicLocalData[SNCode1].SideLaser_短边4_1 = hImage4.CropRectangle1(Convert.ToInt32(短边长度4_1.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度4_1.Trim().Split(',')[1]), width4);

                                        Machine.DicLocalData[SNCode1].SideLaser_短边3_2 = hImage13.CropRectangle1(Convert.ToInt32(短边长度3_2.Trim().Split(',')[0]), 0, Convert.ToInt32(短边长度3_2.Trim().Split(',')[1]), width13);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边1_3 = hImage21.CropRectangle1(Convert.ToInt32(长边长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度1_1.Trim().Split(',')[1]), width21);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边2_3 = hImage22.CropRectangle1(Convert.ToInt32(长边长度2_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度2_1.Trim().Split(',')[1]), width22);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边3_3 = hImage23.CropRectangle1(Convert.ToInt32(长边长度3_1.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度3_1.Trim().Split(',')[1]), width23);

                                        Machine.DicLocalData[SNCode1].SideLaser_长边3_4 = hImage33.CropRectangle1(Convert.ToInt32(长边长度3_2.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度3_2.Trim().Split(',')[1]), width33);
                                        Machine.DicLocalData[SNCode1].SideLaser_长边4_4 = hImage34.CropRectangle1(Convert.ToInt32(长边长度4_2.Trim().Split(',')[0]), 0, Convert.ToInt32(长边长度4_2.Trim().Split(',')[1]), width34);
                                    }
                                    catch
                                    {
                                        string path3D_err = $"D:\\1治具\\{SNCode1}";
                                        if (!FileUtils.IsExistDirectory(path3D_err)) FileUtils.CreateDirectory(path3D_err);
                                        HOperatorSet.WriteImage(hImage1, "tiff", 0, $"{path3D_err}\\hImage1.tiff");
                                        HOperatorSet.WriteImage(hImage2, "tiff", 0, $"{path3D_err}\\hImage2.tiff");
                                        HOperatorSet.WriteImage(hImage3, "tiff", 0, $"{path3D_err}\\hImage3.tiff");
                                        HOperatorSet.WriteImage(hImage4, "tiff", 0, $"{path3D_err}\\hImage4.tiff");
                                        HOperatorSet.WriteImage(hImage13, "tiff", 0, $"{path3D_err}\\hImage13.tiff");
                                        HOperatorSet.WriteImage(hImage21, "tiff", 0, $"{path3D_err}\\hImage21.tiff");
                                        HOperatorSet.WriteImage(hImage22, "tiff", 0, $"{path3D_err}\\hImage22.tiff");
                                        HOperatorSet.WriteImage(hImage23, "tiff", 0, $"{path3D_err}\\hImage23.tiff");
                                        HOperatorSet.WriteImage(hImage33, "tiff", 0, $"{path3D_err}\\hImage33.tiff");
                                        HOperatorSet.WriteImage(hImage34, "tiff", 0, $"{path3D_err}\\hImage34.tiff");
                                        MessageBox.Show("侧激光图像裁剪异常！"); ;
                                    }

                                    hImage1 = Machine.DicLaser["上激光"].HeightImage(5000);
                                    if (GetImageStatus(new List<string>() { "上激光" }, new List<HImage>() { hImage1 }, Step) != StationStep.End)
                                    {
                                        if (ConsumerAdress == "NVT")
                                            Step = StationStep.移动到短边起始位_4062_NVT;
                                        else
                                            Step = StationStep.移动到短边起始位_4062;
                                        break;
                                    }
                                    hImage1.GetImageSize(out width1, out height1);

                                    Machine.DicLocalData[SNCode1].UpLaser = hImage1.CropRectangle1(Convert.ToInt32(上激光长度1_1.Trim().Split(',')[0]), 0, Convert.ToInt32(上激光长度1_1.Trim().Split(',')[1]), width1);
                                    EventVisoion.OnCarrierUpLaserRefresh(new EventVisoion.ImageRefreshEventArgs()
                                    {
                                        SN = SNCode1
                                    });
                                    Step = StationStep.移动到上相机拍照位2拍照;
                                }
                            }
                        }
                        else
                            Step = StationStep.移动到上相机拍照位2拍照;
                        break;
                    case StationStep.移动到上相机拍照位2拍照:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["上相机拍照位2"]))
                        {
                            告知2号载具允许激光扫描 = true;
                            Step = StationStep.上相机拍照位2;
                        }
                        break;
                    case StationStep.上相机拍照位2:
                        if (StationManager.MachineProductionMode != RunningModeEnum.EmptyMode)
                        {
                            if (!ProjectName.Contains("4062"))
                            {
                                Machine.DicLight[治具1上CCD光源3名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].UpCamImage_3 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                Machine.DicLight[治具1上CCD光源4名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].UpCamImage_4 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                if (GetImageStatus(new List<string>() { "上相机3", "上相机4" }, new List<HImage>() {
                                Machine.DicLocalData[SNCode1].UpCamImage_3, Machine.DicLocalData[SNCode1].UpCamImage_4 }, Step) != StationStep.End)
                                {
                                    break;
                                }
                                Task.Run(() => { Machine.DicLight[治具1上CCD光源4名称].Close(); });
                            }
                            else
                            {
                                Machine.DicLight[治具1上CCD光源2名称].Opens(ConsumerAdress, ProjectName, "上相机");
                                PublicMethod.Delay(光源打开延时);
                                Machine.DicLocalData[SNCode1].UpCamImage_2 = PublicMethod.GradImage("上相机", Machine.DirExp["上相机"]);
                                if (GetImageStatus(new List<string>() { "上相机2" }, new List<HImage>() {
                                 Machine.DicLocalData[SNCode1].UpCamImage_2 }, Step) != StationStep.End)
                                {
                                    break;
                                }
                                Task.Run(() =>
                                {
                                    Machine.DicLight[治具1上CCD光源1名称].Close();
                                    Machine.DicLight[治具1上CCD光源2名称].Close();
                                });
                            }
                            EventVisoion.OnCarrierTopLaserRefresh(new EventVisoion.ImageRefreshEventArgs()
                            {
                                SN = SNCode1
                            });
                        }
                        告知2号载具允许到出料位 = false;
                        Step = StationStep.移动到出料位;
                        break;
                    case StationStep.移动到出料位:
                        if (Measure2.Instance.告知1号载具允许到出料位)
                        {
                            if (MotionControl.AxesMove(Machine.DicPos[Name]["出料位"]))
                            {
                                告知2号载具允许上相机拍照位 = true;
                                告知中转平台允许到接料位 = true;
                                Step = StationStep.等待物料取走;
                            }
                        }
                        break;
                    case StationStep.等待物料取走:
                        if (TransitPlatform.Instance.告知量测1接料完成)
                        {
                            PublicMethod.OffVacuum(ListVacuum);
                            TransitPlatform.Instance.告知量测1接料完成 = false;
                            Step = StationStep.GRR模式判断;
                        }
                        break;
                    case StationStep.GRR模式判断:
                        if (StationManager.MachineProductionMode == RunningModeEnum.GRRMode)
                        {
                            LocalGRRCount++;
                            if (LocalGRRCount == GRR循环次数)
                            {
                                LocalGRRCount = 0;
                            }
                            else
                            {
                                Step = StationStep.等待GRR物料归回;
                                break;
                            }
                        }
                        Step = StationStep.移动到出料安全位;
                        break;
                    case StationStep.移动到出料安全位:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["出料安全位"]))
                        {
                            告知2号载具允许到出料位 = true;
                            Step = StationStep.End;
                        }
                        break;
                    case StationStep.等待GRR物料归回:
                        if (TransitPlatform.Instance.告知量测1GRR物料放料完成)
                        {
                            if (MotionControl.AxesMove(Machine.DicPos[Name]["接料等待位"]))
                            {
                                TransitPlatform.Instance.告知量测1GRR物料放料完成 = false;
                                Step = StationStep.GRR物料移动到接料位;
                            }
                        }
                        break;
                    case StationStep.GRR物料移动到接料位:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["接料位"]))
                        {
                            Step = StationStep.接料位信号处理;
                        }
                        break;
                    case StationStep.End:
                        if (MotionControl.AxesMove(Machine.DicPos[Name]["接料等待位"]))
                        {
                            告知2号载具允许到出料位 = true;
                            Step = StationStep.Start;
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                UILog_Error($"[ {logBaseInfo} ActionProcess Thread ERROR] {ex.Message}");
                if (AlarmPause(logBaseInfo, $"当前状态:{Step} 报警异常:{ex.Message}", "点击确定，再试一次；点击取消，继续运行", "再试一次", "继续运行") == DialogResult.OK)
                {

                }
            }
        }

        public override void EmptyActionProcess()
        {
            ActionProcess();
        }

        public override void GRRActionProcess()
        {
            ActionProcess();
        }

        /// <summary>
        /// 工位步骤定义
        /// </summary>
        public enum StationStep
        {
            /// <summary>
            /// 等待机台初始化
            /// </summary>
            [Description("等待机台初始化")]
            WaitMacInit,
            [Description("开始")]
            Start,
            等待允许到接料位,
            判断手动模式,
            等待PLC到位信号,
            等待PLC放料完成,
            手动判断启动,
            接料位信号处理,
            移动到侧相机拍照位,
            侧相机移动到安全位,
            等待允许激光扫描,

            移动到短边起始位_4080,
            移动到短边终点位_4080,
            移动到长边起始位_4080,
            移动到长边终点位_4080,


            移动到短边起始位_4081,
            移动到短边终点位_4081,
            移动到长边起始位_4081,
            移动到长边终点位_4081,
            移动到长边起始位1_4081,
            移动到长边终点位1_4081,


            移动到短边起始位_4084,
            移动到短边终点位_4084,
            移动到短边起始位1_4084,
            移动到短边终点位1_4084,
            移动到长边起始位_4084,
            移动到长边终点位_4084,
            移动到长边起始位1_4084,
            移动到长边终点位1_4084,


            移动到短边起始位_4062,
            移动到短边起始位1_4062,
            移动到长边起始位_4062,
            移动到长边扫描安全位_4062,
            移动到长边起始位1_4062,

            移动到短边起始位_4062_NVT,
            移动到短边起始位1_4062_NVT,
            移动到长边起始位_4062_NVT,
            移动到长边扫描安全位_4062_NVT,
            移动到长边起始位1_4062_NVT,



            上相机拍照位1,
            判断激光图是否扫全,
            移动到上相机拍照位2拍照,
            上相机拍照位2,
            移动到出料位,
            等待物料取走,
            移动到出料安全位,
            GRR模式判断,
            等待GRR物料归回,
            GRR物料移动到接料位,
            [Description("工站完成")]
            End,
        }


        public bool ReadBaracode(string str, bool IsGet_PLC, out string sn)
        {
            bool isClear = false;
            sn = $"NDK{DateTime.Now.ToString("yyyyMMddHHmmssff")}_NDK";
            if (IsGet_PLC)
            {
                int Count = 0;
                string sn1;
            Line:
                if (Line == "右")
                {
                    isClear = Machine.OmronPLC_Up.ReadBool(stCom_2_PLC_PC_B_1);
                    sn1 = Machine.OmronPLC_Up.ReadString(stCom_0_PLC_PC_PanelID1);
                }
                else
                {
                    isClear = Machine.OmronPLC_Up.ReadBool(stCom_3_PLC_PC_B_1);
                    sn1 = Machine.OmronPLC_Up.ReadString(stCom_1_PLC_PC_PanelID1);
                }

                if (Count == 3)
                {
                    if (AlarmPause(logBaseInfo, str + "物料连续扫码3次失败", "点击确定，再试一次；点击取消，继续运行", "再试一次", "继续运行") == DialogResult.OK)
                    {
                        return false;
                    }
                    else
                        sn1 = sn;
                }
                if (sn1 == "")
                {
                    Count++;
                    goto Line;
                }
                else
                    sn = sn1;
            }
            sn += "_" + str;
            if (!Machine.DicLocalData.ContainsKey(sn))
            {
                Machine.AddDicLocalData(sn, new MeasureProduct() { SN = sn.Split('_')[0], whichBlock = whichBlock, Position = str, IsClear_PLC = isClear });
            }
            return true;
        }

        StationStep GetImageStatus(List<string> CameraName, List<HImage> hImage, StationStep stationStep)
        {
            StationStep step = stationStep;
            for (int i = 0; i < CameraName.Count; i++)
            {
                if (hImage[i] == null)
                {
                    if (AlarmPause($"{logBaseInfo}采图异常", $"{CameraName[i]}: 采集异常：", "请检查相机是否掉线及相机参数是否存在异常", " 再次拍照", "忽略继续") == DialogResult.OK)
                    {
                        if (ProjectName.Contains("4062"))
                        {
                            if (CameraName[i].Contains("激光"))
                            {
                                foreach (var item in Machine.DicLaserIp.Keys)
                                {
                                    if (Convert.ToInt32(Machine.DicLaserIp[item][1]) == 0 && item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].DisConnect();
                                        Machine.DicLaser[item].Connect(Machine.DicLaserIp[item][0], Convert.ToInt32(Machine.DicLaserIp[item][1]));
                                    }
                                }

                                foreach (var item in Machine.DicLaserIp.Keys)
                                {
                                    if (Convert.ToInt32(Machine.DicLaserIp[item][1]) != 0 && item.Contains("侧激光"))
                                    {
                                        Machine.DicLaser[item].DisConnect();
                                        Machine.DicLaser[item].Connect(Machine.DicLaserIp[item][0], Convert.ToInt32(Machine.DicLaserIp[item][1]));
                                    }
                                }

                                if (Machine.DicLaserIp.ContainsKey(CameraName[i]) && CameraName[i].Contains("上激光"))
                                {
                                    Machine.DicLaser[CameraName[i]].DisConnect();
                                    Machine.DicLaser[CameraName[i]].Connect(Machine.DicLaserIp[CameraName[i]][0], Convert.ToInt32(Machine.DicLaserIp[CameraName[i]][1]));
                                }
                            }
                        }


                        if (CameraName[i].Contains("侧相机"))
                        {
                            Machine.DicCamera["侧相机"].CloseCamera();
                            Machine.DicCamera["侧相机"].ConnectCamera(Machine.DicCamera["侧相机"].SerialNumber, Machine.DicCamera["侧相机"].FilePath, Machine.DirExp["侧相机"]);
                        }
                        if (CameraName[i].Contains("上相机"))
                        {
                            Machine.DicCamera["上相机"].CloseCamera();
                            Machine.DicCamera["上相机"].ConnectCamera(Machine.DicCamera["上相机"].SerialNumber, Machine.DicCamera["上相机"].FilePath, Machine.DirExp["上相机"]);
                        }
                        return step;
                    }
                }
            }
            return StationStep.End;
        }

        public void ONLaser(int count)
        {
            if (!ProjectName.Contains("4062"))
            {
                switch (count)
                {
                    case 0:
                        Machine.DicOutputIO["侧激光1触发"].OFF();
                        Machine.DicOutputIO["侧激光2触发"].OFF();
                        Machine.DicOutputIO["侧激光3触发"].OFF();
                        Machine.DicOutputIO["侧激光4触发"].OFF();
                        break;
                    case 1:
                        //4081
                        Machine.DicOutputIO["侧激光1触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1触发"].OFF();
                        break;
                    case 2:
                        //4084
                        Machine.DicOutputIO["侧激光4触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光4触发"].OFF();
                        break;
                    case 5:
                        //4081 4084
                        Machine.DicOutputIO["侧激光1触发"].ON();
                        Machine.DicOutputIO["侧激光2触发"].ON();
                        Machine.DicOutputIO["侧激光3触发"].ON();
                        Machine.DicOutputIO["侧激光4触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1触发"].OFF();
                        Machine.DicOutputIO["侧激光2触发"].OFF();
                        Machine.DicOutputIO["侧激光3触发"].OFF();
                        Machine.DicOutputIO["侧激光4触发"].OFF();
                        break;
                    case 4:
                        //4080  4081  4084
                        Machine.DicOutputIO["侧激光1触发"].ON();
                        Machine.DicOutputIO["侧激光2触发"].ON();
                        Machine.DicOutputIO["侧激光4触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1触发"].OFF();
                        Machine.DicOutputIO["侧激光2触发"].OFF();
                        Machine.DicOutputIO["侧激光4触发"].OFF();
                        break;
                    case 7:
                        //4084
                        Machine.DicOutputIO["侧激光1触发"].ON();
                        Machine.DicOutputIO["侧激光4触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1触发"].OFF();
                        Machine.DicOutputIO["侧激光4触发"].OFF();
                        break;
                }
                Thread.Sleep(10);
            }
            else
            {
                if (ConsumerAdress != "NVT" && count == 0)
                {
                    Machine.DicOutputIO["侧激光1触发"].OFF();
                    Machine.DicOutputIO["侧激光2触发"].OFF();
                    Machine.DicOutputIO["侧激光3触发"].OFF();
                    Machine.DicOutputIO["侧激光4触发"].OFF();
                }
            }
        }

        public void OFFLaser(int count)
        {
            if (!ProjectName.Contains("4062"))
            {
                switch (count)
                {
                    case 0:
                        Machine.DicOutputIO["侧激光1结束触发"].OFF();
                        Machine.DicOutputIO["侧激光2结束触发"].OFF();
                        Machine.DicOutputIO["侧激光3结束触发"].OFF();
                        Machine.DicOutputIO["侧激光4结束触发"].OFF();
                        break;
                    case 1:
                        //4081
                        Machine.DicOutputIO["侧激光1结束触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1结束触发"].OFF();
                        break;
                    case 2:
                        //4084
                        Machine.DicOutputIO["侧激光4结束触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光4结束触发"].OFF();
                        break;
                    case 5:
                        //4081 4084
                        Machine.DicOutputIO["侧激光1结束触发"].ON();
                        Machine.DicOutputIO["侧激光2结束触发"].ON();
                        Machine.DicOutputIO["侧激光3结束触发"].ON();
                        Machine.DicOutputIO["侧激光4结束触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1结束触发"].OFF();
                        Machine.DicOutputIO["侧激光2结束触发"].OFF();
                        Machine.DicOutputIO["侧激光3结束触发"].OFF();
                        Machine.DicOutputIO["侧激光4结束触发"].OFF();
                        break;
                    case 4:
                        //4080 4084
                        Machine.DicOutputIO["侧激光1结束触发"].ON();
                        Machine.DicOutputIO["侧激光2结束触发"].ON();
                        Machine.DicOutputIO["侧激光4结束触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1结束触发"].OFF();
                        Machine.DicOutputIO["侧激光2结束触发"].OFF();
                        Machine.DicOutputIO["侧激光4结束触发"].OFF();
                        break;
                    case 7:
                        //4084
                        Machine.DicOutputIO["侧激光1结束触发"].ON();
                        Machine.DicOutputIO["侧激光4结束触发"].ON();
                        Thread.Sleep(20);
                        Machine.DicOutputIO["侧激光1结束触发"].OFF();
                        Machine.DicOutputIO["侧激光4结束触发"].OFF();
                        break;
                }
            }
        }

        public int SetLaserParam()
        {
            if (ProjectName.Contains("4062"))
                return 0;

            bool bb = false;
            foreach (var item in Machine.DicLaser.Keys)
            {
                if (item.Contains("激光"))
                    bb = true;
            }
            if (bb)
            {
                Machine.DicLaser["侧激光1"].Stop();
                Machine.DicLaser["侧激光2"].Stop();
                Machine.DicLaser["侧激光3"].Stop();
                Machine.DicLaser["侧激光4"].Stop();
                Machine.DicLaser["上激光"].Stop();
                if (Line == "右")
                {
                    Machine.DicLaser["下激光1"].Stop();
                    Machine.DicLaser["下激光2"].Stop();
                }

                List<bool> list = new List<bool>();
                if (CurProType.Contains("Block"))
                {
                    list.Add(Machine.DicLaser["侧激光1"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光2"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光3"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光4"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["上激光"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["下激光1"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["下激光2"].SwitchJob("1"));

                }
                else if (CurProType == "cutting")
                {
                    list.Add(Machine.DicLaser["侧激光1"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["侧激光2"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["侧激光3"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["侧激光4"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["上激光"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["下激光1"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["下激光2"].SwitchJob("0"));

                }
                else if (CurProType == "Uncutting")
                {
                    list.Add(Machine.DicLaser["侧激光1"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光2"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光3"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["侧激光4"].SwitchJob("1"));
                    list.Add(Machine.DicLaser["上激光"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["下激光1"].SwitchJob("0"));
                    list.Add(Machine.DicLaser["下激光2"].SwitchJob("2"));

                }
                if (list.Contains(false))
                {
                    AppendUiLog.Log($"激光参数切换异常！", LogType.Error);
                    return 8;
                }
                else
                {
                    AppendUiLog.Log($"激光参数切换成功！", LogType.Info);
                }
            }
            return 0;
        }
    }
}
